package com.example.dell.test1;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by klren on 2016/6/1.
 */
public class UserService  {
    private  DatabaseHelper dbHelper;
    public UserService(Context context){
        dbHelper = new DatabaseHelper(context);
    }

    /**
     * 登录服务
     */
    public boolean login(String username,String password){
        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        String sql = "select * from user where username=? and password=?";
        Cursor cursor = sdb.rawQuery(sql,new String[]{username,password});
        if (cursor.moveToFirst()==true){
            cursor.close();
            return true;
        }
        return false;
    }

    /**
     * 注册服务
     */
    public boolean register(User user){
        SQLiteDatabase sdb = dbHelper.getReadableDatabase();
        String sql = "insert into user(username,password) values(?,?)";
        Object obj[] = {user.getUsername(),user.getPassword()};
        sdb.execSQL(sql,obj);
        return true;
    }

}
